package com.lzy.system.organization.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lzy.conf.JSONResult;
import com.lzy.system.organization.dto.SysConfigAddDTO;
import com.lzy.system.organization.entity.SysConfig;
import com.lzy.system.organization.service.ISysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.yaml.snakeyaml.Yaml;

import java.util.Map;

/**
 * <p>
 * 系统设置 前端控制器
 * </p>
 *
 * @author lcc
 * @since 2023-12-09
 */
@RestController
@RequestMapping("/sysConfig")
@Api(tags = "系统设置")
public class SysConfigController {
    ISysConfigService iSysConfigService;

    @Autowired
    public SysConfigController(ISysConfigService iSysConfigService) {
        this.iSysConfigService = iSysConfigService;
    }
    @ApiOperation("保存系统设置")
    @RequestMapping(value = "save", method = RequestMethod.POST)
    public JSONResult save(@ApiParam("保存系统设置") @RequestBody @Validated() SysConfigAddDTO sysConfigAddDTO) throws Exception {
        iSysConfigService.saveSysConfig(sysConfigAddDTO);
        return JSONResult.ok();
    }

    @ApiOperation("获取系统设置")
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public JSONResult get() throws Exception {
        SysConfig data = iSysConfigService.getOne(new QueryWrapper() {{
            last("limit 1");
        }},true);
        return JSONResult.ok(data);
    }

    @ApiOperation("获取系统设置")
    @RequestMapping(value = "/getJson", method = RequestMethod.GET)
    public JSONResult getJson() throws Exception {
        return JSONResult.ok(iSysConfigService.getJson());
    }

}
